/*
 * Copyright 2017 Zhihu Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.zhihu.matisse.engine.impl;

import com.squareup.picasso.Picasso;
import com.zhihu.matisse.engine.ImageEngine;
import ohos.agp.components.Image;
import ohos.agp.components.element.Element;
import ohos.app.Context;
import ohos.utils.net.Uri;

/**
 * {@link ImageEngine} implementation using Picasso.
 */

public class PicassoEngine implements ImageEngine {

    @Override
    public void loadThumbnail(Context context, int resize, Element placeholder, Image imageView, Uri uri) {
        if (resize == 0){
            Picasso.get().load(uri).placeholder(placeholder)
                    .centerCrop()
                    .tag(context)
                    .into(imageView);
        }else {
            Picasso.get().load(uri).placeholder(placeholder)
                    .resize(resize, resize)
                    .centerCrop()
                    .tag(context)
                    .into(imageView);
        }


    }

    @Override
    public void loadGifThumbnail(Context context, int resize, Element placeholder, Image imageView,
                                 Uri uri) {
        loadThumbnail(context, resize, placeholder, imageView, uri);
    }

    @Override
    public void loadImage(Context context, int resizeX, int resizeY, Image imageView, Uri uri) {
        if (resizeX == 0 && resizeY == 0){
            Picasso.get().load(uri).priority(Picasso.Priority.HIGH).tag(context)
                    .centerInside().into(imageView);
        }else {
            Picasso.get().load(uri).resize(resizeX, resizeY).priority(Picasso.Priority.HIGH).tag(context)
                    .centerInside().into(imageView);
        }

    }

    @Override
    public void loadGifImage(Context context, int resizeX, int resizeY, Image imageView, Uri uri) {
        loadImage(context, resizeX, resizeY, imageView, uri);
    }

    @Override
    public boolean supportAnimatedGif() {
        return false;
    }
}
